/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package csse3004.GD.PC;

//Includes
import csse3004.GD.DA.PollCreatorDA;
import javax.servlet.ServletException;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.SimpleFormController;

/**
 *
 * @author Lewis Kelly 42007689
 */

public class newMCQController extends SimpleFormController {
    protected final Log logger = LogFactory.getLog(getClass());
    
    //Create Instance of User
    private PollCreatorService pollCreatorService = new PollCreatorDA();
    
    //Create a new ModelAndView to return
    ModelAndView mnv = new ModelAndView("success");
    
    @Override
    public ModelAndView onSubmit(Object command) throws ServletException { 
        String success = "Your question has been successfully submitted!!";
        String failure = "Your question was not successfully submitted, please try again";
        
        //Creates an instance of the logic class
        newMCQ qu = (newMCQ) command;
        
        //Get all of the variables needed for database function
        String qtext = qu.getQuestionText();
        String qtype = qu.getStyle();
        String qtemplate = "No";
        String qrank = "No";
        String qdemo = "No";
        String qcomp = "No";
        int id = qu.getPollID();
        
        //Logger messages for testing
        logger.info("I've Got: "+qtext+" for qtext");
        logger.info("I've Got: "+id+" for id");
        logger.info("I've Got: "+qtype+" for type");
        
        //Function that adds an new Multiple choice function to the database
        pollCreatorService.addMCQuestion(qtext, qtype, qtemplate, qrank, qdemo, qcomp, id);

        logger.info("returning newMCQ page");
        mnv.addObject("succ", success);
        return mnv;
    }
}
